<?php
/**
 * Yii view dataTable
 *
 * @author luunguyen
 * @since Dec 24, 2012 - 2:31:35 PM
 */
?>
<div class="grid <?php echo isset($this->htmlOptions['class']) ? $this->htmlOptions['class'] : '' ?>">
    <div class="grid-title">
        <div class="pull-left">
            <?php echo $this->title ?>
        </div>
        <?php if ($this->linkCreate != ''): ?>
            <div class="pull-right span1">
                <a href="<?php echo $this->linkCreate ?>" class="btn btn-primary">
                    <?php echo Yii::t('datatable', 'Create') ?>
                </a>
            </div>
        <?php endif; ?>
        <?php if (!$this->noPaging): ?>
            <form class="pull-right">
                <select name="limit" style="width: 70px" onchange="this.form.submit();">
                    <?php
                    foreach ($this->limitArray as $limit):
                        ?>
                        <?php $select = ($this->currentLimit == $limit) ? "selected" : ""; ?>
                        <option value="<?php echo $limit ?>" <?php echo $select ?> >
                            <?php echo $limit ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </form>
        <?php endif; ?>           
        <?php if ($this->linkViewMore != ''): ?>
            <a href="<?php echo $this->linkViewMore ?>" class="btn btn-mini pull-right">
                <?php echo Yii::t('datatable', 'View more') ?>
            </a>
        <?php endif; ?>
        <div class="clear"></div>
    </div>
    <?php if (!empty($this->columns)): ?>
        <table class="<?php echo $this->tableClass ?>">
            <thead>
                <tr>
                    <th>#</th>
                    <?php foreach ($this->columns as $attribute): ?>
                        <th>
                            <?php echo $this->displayHeader($attribute) ?>
                        </th>
                    <?php endforeach; ?>
                    <?php if (!$this->noAction): ?>
                        <th>
                            <?php echo Yii::t('datatable', 'Action') ?>
                        </th>
                    <?php endif; ?>
                </tr>
            </thead>
            <tbody>                    
                <?php $i = $pages->currentPage * $this->currentLimit; ?>                
                <?php if (!empty($data)): ?>
                    <?php foreach ($data as $item): ?>
                        <?php $i++ ?>
                        <?php $itemClass = ($i % 2 != 0) ? 'even_gradeA' : 'odd_gradeA' ?>
                        <tr class="<?php echo $itemClass ?>">
                            <td><?php echo $i ?></td>
                            <?php $j = 1; ?>
                            <?php foreach ($this->columns as $attribute): //Hiển thị các attribute  ?>
                                <td style="max-width: 250px;text-align: justify">
                                    <?php if ($j == 1 && $this->linkViewMore == ''): ?>
                                        <?php echo CHtml::link($this->displayItem($item, $attribute), $this->getActionLink($item, 'update')); ?>
                                    <?php else: ?>
                                        <?php echo $this->displayItem($item, $attribute) ?>
                                    <?php endif; ?>
                                </td>
                                <?php $j++; ?>
                            <?php endforeach; ?>

                            <?php if (!$this->noAction): // Không hiển thị nút Action ?>
                                <td>                                    
                                    <?php echo $this->createActionButton($item); ?>
                                </td>
                            <?php endif; ?>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    <?php endif; ?>
</div>
<?php if (!$this->noPaging): ?>
    <br/>
    <div class="pagination pagination-centered">
        <?php
        $this->widget('MyLinkPager', array(
            'pages' => $pages,
            'header' => '',
            'maxButtonCount' => $this->maxPageButton,
            'nextPageLabel' => '&raquo;',
            'firstPageLabel' => '←',
            'lastPageLabel' => '→',
            'prevPageLabel' => '&laquo;',
            'selectedPageCssClass' => 'active',
        ))
        ?>
    </div>
<?php endif; ?>